-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Toggle block comments #4718
Toggle block comments #4718
Conversation
I think I can make it so that there is one command that can toggle block and line comments,, then seperate commands for just block and line toggling, my proposed algorithm is: if only one of single line token or block tokens exist, toggle that, else do the following:
|
I implemented the above, and then separated line comment toggling into it's own command that is under there is definitely ways to make block commenting smarter, for example comment a block if selection is surrounded by only whitespace and then comment token or uncomment block that is surrounded by other characters then whitespace in a selection(though I think this could actually extend the comment block maybe). This could be saved for future pr if this functionality is wanted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this! Comment as discussed in matrix
This PR should now be ready for review, some things to note:
|
Thanks for working on this! I think block comments are useful to have in particular for languages that do not have line comments. I had this in my daily driver for a while and have some thoughts. I think automatically switching between line comments and block commenys based upon whether more then 1 char is selectes is nice to have but I found myself frustrated by this as a default. For languages that support them I almost always want line comments because of the more granular control (comment ten lines, later uncomment only two of them or move some part of the comment elsewhere without having to add new commentnstsrt/end) so I would prefer to keep that as is. I think the automatic option is still useful but perhaphs as a secondary command (maybe mapped to If other people (@archseer whatdo you think?) prefer the default as in this PR I think its fine too as the I keybindings can be swappes in my config. I think the suggesting about using block comments as a line comment fallback should definitely be implement |
Thanks for your input @pascalkuthe it's very helpful, and unless someone else objects I think I will implement it as the default. This seems simpler and more intuitive to the user, I don't have time today to implement this but it was in the back of my mind after I marked it for review so it shouldn't take me too long. |
sorry for the wait on this I have been pretty busy, the new relevant changes are more inline with @pascalkuthe suggestions(if you have the time to take a look at the new behaviour that would be appreciated, I am sure you are pretty busy right now so it's totally okay if you don't do an actual review) the key changes are summarized here:
whats left at this point is to add this to the docs and look into making some more meaningful tests |
How will this affect the default |
Only effects if there is no line |
@gabydd Is this ready for review? |
Yep except it still needs the documentation, the one thing I am still unsure about is if we want to change how the config for block comments is to make it a map to easier add the token for continue comments, or do we think that can be a seperate option? |
ok thanks for letting me know. I will think about that during review |
Just fixed the merge conflicts I also squashed the pr to one commit so it's easier to rebase when there are conflicts if we want I can make one commit the code changes and the other the languages.toml changes |
3b4ea22
to
8146de6
Compare
(Also closes #4009 but I can't link the issue because the GH UI is terribble) |
This only fixes that for block comments, I didn't want to change the functionality of line comments in this pr |
What we could do is for languages without a block comment token, when using the toggle_block_comments it would only add or remove from the start of the selection as if you had a block comment that was the line comment on the left and an empty string on the right |
redundant_clone seems to have some false positives: rust-lang/rust-clippy#10577 |
Let's add some |
Using this since last week and works great, thanks for putting this up! |
28428c3
this is an initial implementation of toggling block comments which fixes #1505 it still needs
can we get comment tokens from treesitterany other feedback appreciated, this is still a draft and nothing is set in stone
some implementation notes:
i tried to do the same thing aspascal figured this outfind_first_non_whitespace_character
infind_last_non_whitespace_character
but apparentlyChars
doesn't implementDoubleEndedIterator
so I just iterate over a reversed range of chars len instead. I don't think this should have performance implications on really long selections, but someone else might know better.video of it in action